package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("/hello")
public class HelloController {
    @GetMapping
    public String test(Model model) {
        model.addAttribute("name", "小明");
        Student stu = new Student();
        stu.setName("张伟");
        stu.setAge(21);
        model.addAttribute("stu", stu);
        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model) {
        // -------------list-----------
        Student stu1 = new Student();
        stu1.setName("小明");
        stu1.setAge(19);
        stu1.setBirthday(new Date());
        stu1.setMoney(19.9F);
        Student stu2 = new Student();
        stu2.setName("小红");
        stu2.setAge(18);
        stu2.setBirthday(new Date());
        stu2.setMoney(18.9F);
        List<Student> stus = new ArrayList<>();
        stus.add(stu1);
        stus.add(stu2);
        model.addAttribute("stus", stus);
        // -------------map-----------
        Map<String, Student> stuMap = new HashMap<>();
        stuMap.put("stu1", stu1);
        stuMap.put("stu2", stu2);
        model.addAttribute("stuMap", stuMap);
        return "02-list";
    }

    @GetMapping("/innerFunc")
    public String innerFunc(Model model) {
        // -------------list-----------
        Student stu1 = new Student();
        stu1.setName("小帅");
        stu1.setAge(19);
        stu1.setBirthday(new Date());
        stu1.setMoney(19.9F);
        Student stu2 = new Student();
        stu2.setName("小美");
        stu2.setAge(20);
        stu2.setBirthday(new Date());
        stu2.setMoney(18.9F);
        List<Student> stus = new ArrayList<>();
        stus.add(stu1);
        stus.add(stu2);
        model.addAttribute("stus", stus);
        model.addAttribute("today", new Date());
        model.addAttribute("point", 1534852);
        return "04-innerFunc";
    }
}
